<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/8/23
  Time: 16:33
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>客户开发计划 > 制定计划</title>

    <link rel="shortcut icon" href="<c:url value="/images/favicon.ico"/>" type="image/x-icon"/>
    <script src="<c:url value="/js/jquery-1.9.1.min.js"/>"></script>
    <script src="<c:url value="/layui/layui.js"/>"></script>
    <link rel="stylesheet" type="text/css" href="<c:url value="/layui/css/layui.css"/>">

    <script src="<c:url value="/js/my/commons.js"/>"></script>
    <style>
        .container {
            width: 1200px;
            margin: 100px auto;
        }
        table{
            width: 100%;
        }
    </style>

</head>
<body>

<form class="layui-form layui-form-pane" style="margin-left: 475px">

    <div class="layui-form-item" style="margin-top: 120px;">
        <%--    编号    --%>
        <div class="layui-inline">
            <label class="layui-form-label">编号：</label>
            <div class="layui-input-inline">
                <input id="id" name="id" lay-verify="id"
                       type="text" autocomplete="off" class="layui-input" readonly="readonly" placeholder="从数据库导入">
            </div>
        </div>
        <%--    机会来源    --%>
        <div class="layui-inline" style="margin-left: 100px">
            <label class="layui-form-label">机会来源：</label>
            <div class="layui-input-inline">
                <input id="source" name="source" lay-verify="source"
                       type="text" autocomplete="off" class="layui-input" placeholder="从数据库导入" readonly="readonly">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <%--     客户名称   --%>
        <div class="layui-inline">
            <label class="layui-form-label">客户名称：</label>
            <div class="layui-input-inline">
                <input id="name" name="name" lay-verify="name"
                       type="text" autocomplete="off" class="layui-input" placeholder="从数据库导入" readonly="readonly">
            </div>
        </div>
        <%--     成功几率   --%>
        <div class="layui-inline" style="margin-left: 100px">
            <label class="layui-form-label">成功几率：</label>
            <div class="layui-input-inline">
                <input id="success" name="success " lay-verify="success "
                       type="text" autocomplete="off" class="layui-input" placeholder="从数据库导入" readonly="readonly">
            </div>
        </div>
    </div>

    <%--    概要   --%>
    <div class="layui-form-item">
        <label class="layui-form-label">概要：</label>
        <div class="layui-input-block" style="width: 615px">
            <input id="general" name="general" lay-verify="general"
                   type="text" autocomplete="off" placeholder="从数据库导入" class="layui-input" readonly="readonly">
        </div>
    </div>

    <div class="layui-form-item">
        <%--    联系人    --%>
        <div class="layui-inline">
            <label class="layui-form-label">联系人：</label>
            <div class="layui-input-inline">
                <input id="customerName" name="customerName" lay-verify="customerName"
                       type="text" autocomplete="off" class="layui-input" placeholder="从数据库导入" readonly="readonly">
            </div>
        </div>
        <%--    联系电话    --%>
        <div class="layui-inline" style="margin-left: 100px">
            <label class="layui-form-label">联系电话：</label>
            <div class="layui-input-inline">
                <input id="mobile_phone" name="mobile_phone" lay-verify="mobile_phone"
                       type="text" autocomplete="off" class="layui-input" placeholder="从数据库导入" readonly="readonly">
            </div>
        </div>
    </div>

    <%--    机会描述   --%>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label" style="width: 723px">机会描述：</label>
        <div class="layui-input-block" style="width: 723px">
            <textarea id="description" name="description"
                      placeholder="从数据库导入" class="layui-textarea" readonly="readonly"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <%--     创建人   --%>
        <div class="layui-inline">
            <label class="layui-form-label">创建人：</label>
            <div class="layui-input-inline">
                <input id="creater" name="creater" lay-verify="creater"
                       type="text" autocomplete="off" class="layui-input" readonly="readonly" placeholder="从数据库导入">
            </div>
        </div>
        <%--     创建时间   --%>
        <div class="layui-inline" style="margin-left: 100px">
            <label class="layui-form-label">创建时间：</label>
            <div class="layui-input-inline">
                <input id="create_date" name="create_date" lay-verify="create_date"
                       type="text" placeholder="从数据库导入" autocomplete="off" class="layui-input" readonly="readonly">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <%--     指派给谁   --%>
        <div class="layui-inline">
            <label class="layui-form-label">指派：</label>
            <div class="layui-input-inline">
                <input id="Rel_name" name="Rel_name" lay-verify="Rel_name"
                       type="text" placeholder="从数据库导入" autocomplete="off" class="layui-input" readonly="readonly">
            </div>
        </div>
        <%--     指派时间   --%>
        <div class="layui-inline" style="margin-left: 100px">
            <label class="layui-form-label">指派时间：</label>
            <div class="layui-input-inline">
                <input id="allot_date" name="allot_date" lay-verify="allot_date"
                       type="text" placeholder="从数据库导入"  autocomplete="off" class="layui-input" readonly="readonly">
            </div>
        </div>
    </div>

</form>


<div class="layui-fluid" style="height: 500px;padding-left: 310px;padding-right: 310px">
    <div class="layui-card">

        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-userfront-formlist"
             style="padding-left: 175px">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">日期</label>
                    <div class="layui-input-inline">
                        <input type="text" name="date" id="date" lay-verify="datetime" placeholder="yyyy-MM-dd HH:mm:ss"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">内容</label>
                    <div class="layui-input-block">
                        <input id="detail" name="detail"
                               type="text" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <button id="add" name="add" class="layui-btn layuiadmin-btn-useradmin" lay-submit
                            lay-filter="LAY-user-front-search">
                        <i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"></i>
                    </button>
                </div>

            </div>
        </div>


        <button id="execute" type="button" class="layui-btn">执行计划</button>

        <table id="test" lay-filter="test" class="layui-hide" height=100></table>



        <script type="text/html" id="table-useradmin-webuser">

            <a id="edit" lay-event="edit" class="layui-btn layui-btn-normal layui-btn-xs">
                <i class="layui-icon layui-icon-edit"></i>保存
            </a>

            <a id="del" lay-event="del" class="layui-btn layui-btn-danger layui-btn-xs">
                <i class="layui-icon layui-icon-delete"></i>删除
            </a>

        </script>



    </div>
</div>

<script>
    layui.use(['form','table','layer','laydate','layedit'], function(){
        var $ = layui.$
            ,table = layui.table
            ,form = layui.form
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,layedit = layui.layedit;

        //日期
        laydate.render({
            elem: '#date',
            type:"datetime",
            format:"yyyy-MM-dd HH:mm:ss"
        });

        //表格
        table.render({
            elem: '#test'
            ,url: '<c:url value="/dev_plan_Page.do"/>'
            ,cols: [[
                ,{field: 'id', title: 'id',style:'display:none;'}
                ,{field: 'linkman_id', title: 'linkman_id',style:'display:none;'}
                ,{field: 'manager_id', title: 'manager_id',style:'display:none;'}
                // ,{field: 'rownu', title: 'id', width: 54}
                ,{field: 'create_time', title: '日期', width: 160, align:'center'}
                ,{field: 'detail', title: '计划项（可进行修改）', minWidth: 100,width:601,edit: 'text'}
                ,{title: '操作', width: 314, align:'center', fixed: 'right', toolbar: '#table-useradmin-webuser'}
            ]]
            ,text: '对不起，加载出现异常！'
            /**
             * response:{
                statusName: '自定义的参数名称' ,// 对应 code
                msgName: '自定义的参数名称' , // 对应 msg
                countName: '自定义的参数名称' , // 对应 count
                dataName: '自定义的参数名称' // 对应 data
                }
             */
            ,response: {
                statusName: 'code',// 对应 code
                msgName: 'mag', // 对应 msg
                countName: 'count', // 对应 count
                dataName: 'data'  // 对应 data
            }
            ,text:{none: '无数据'}
        });
        $('table.layui-table thead tr th:eq(0)').addClass('layui-hide');
        $('table.layui-table thead tr th:eq(1)').addClass('layui-hide');
        $('table.layui-table thead tr th:eq(2)').addClass('layui-hide');

        //-----------------------------------------------------------------------------------------------

        //添加按钮
        $("#add").click(function () {
            var date = $("#date").val();
            var detail = $("#detail").val();
            var customerName = $("#customerName").val();
            $.ajax({
                url: '<c:url value="/planAdd.do"/>',
                type:'post',
                dataType:'text',
                data:"&date="+date+"&detail="+detail+"&customerName="+customerName,
                success:function(msg){
                    if (msg=="success"){
                        layer.confirm('添加成功', {icon: 1, title:'提示',offset:'200px'}, function(index){
                            //do something

                            layer.close(index);
                            location.href = "dev_plan.jsp";
                        });
                    }else{
                        layer.confirm('添加失败', {icon: 2, title:'提示',offset:'200px'}, function(index){
                            //do something

                            layer.close(index);
                        });
                    }
                }
            })
        })


        //-----------------------------------------------------------------------------------------------

        //删除
        function deleteWay(id) {
            $.get('<c:url value="/deleteToPlan.do"/>',
                {"id": id},
                function (data) {
                    if (data!="success"){
                        layer.confirm('刪除成功', {icon: 1, title:'提示',offset:'200px'}, function(index){
                            //do something

                            layer.close(index);
                            location.href="dev_plan.jsp";
                        });
                    }else{
                        layer.confirm('刪除失败', {icon: 2, title:'提示',offset:'200px'}, function(index){
                            //do something
                            layer.close(index);
                            location.href="dev_plan.jsp";
                        });
                    }
                })
        }

        function upd(id,detail) {
            $.get('<c:url value="/updDetail.do"/>',
                {"id": id,"detail":detail},
                function (data) {
                    if (data="success"){
                        layer.confirm('保存成功', {icon: 1, title:'提示',offset:'200px'}, function(index){
                            //do something

                            layer.close(index);
                        });
                    }else{
                        layer.confirm('保存失败', {icon: 2, title:'提示',offset:'200px'}, function(index){
                            //do something

                            layer.close(index);
                        });
                    }
                })
        }




        //按钮操作
        //监听工具条
        table.on('tool(test)', function(obj){

            if (obj.event === 'del') {
                layer.confirm('确定删除吗', {icon: 3, title:'提示',offset:'200px'}, function (index) {
                    obj.del();
                    deleteWay(obj.data.id);
                    layer.close(index);
                });
            }
            else if(obj.event === 'edit'){
                layer.confirm('确定保存吗', {icon: 3, title:'提示',offset:'200px'}, function (index) {
                    obj.update();
                    upd(obj.data.id,obj.data.detail);
                    layer.close(index);
                });
            }
        });

        $("#execute").click(function () {
            // alert(JSON.stringify(table.cache));
            var data=JSON.stringify(table.cache);
            $.ajax({
                url: '<c:url value="/execute.do"/>',
                type:'post',
                dataType:'text',
                data:{
                    jsonString : data
                },
                success:function(msg){
                    if (msg=="success"){
                        layer.confirm('执行成功', {icon: 1, title:'提示',offset:'200px'}, function(index){
                            //do something
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            layer.close(index);
                        });
                    }else{
                        layer.confirm('您没有制定计划', {icon: 2, title:'提示',offset:'200px'}, function(index){
                            //do something

                            layer.close(index);
                        });
                    }
                }
            })
        })

        // document.getElementById('xzjh').addEventListener('click',function (data) {
        //     var oldData =  table.cache["test"];
        //     var data1={};
        //     oldData.push(data1);
        //     table.reload('test',{data : oldData});
        // });


    });

    $(function () {

        <%--alert(${sessionScope.planeGetSj.get("sale_opportunityId")});--%>
        <%--alert(${sessionScope.planeGetSj.get("source")});--%>
        <%--alert(${sessionScope.planeGetSj.get("customerName")});--%>
        <%--alert(${sessionScope.planeGetSj.get("success")});--%>
        <%--alert(${sessionScope.planeGetSj.get("general")});--%>

        $("#id").val('${sessionScope.planeGetSj.get("sale_opportunityId")}');
        $("#source").val('${sessionScope.planeGetSj.get("source")}');
        $("#name").val('${sessionScope.planeGetSj.get("name")}');
        $("#success").val('${sessionScope.planeGetSj.get("success")}');
        $("#general").val('${sessionScope.planeGetSj.get("general")}');
        $("#customerName").val('${sessionScope.planeGetSj.get("customerName")}');
        $("#mobile_phone").val('${sessionScope.planeGetSj.get("mobile_phone")}');
        $("#description").val('${sessionScope.planeGetSj.get("description")}');
        $("#creater").val('${sessionScope.planeGetSj.get("creater")}');
        $("#create_date").val('${sessionScope.planeGetSj.get("create_date")}');
        $("#Rel_name").val('${sessionScope.planeGetSj.get("Rel_name")}');
        $("#allot_date").val('${sessionScope.planeGetSj.get("allot_date")}');



    })

</script>

</body>
</html>
